package com.app.ui.view.list.swipe;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import android.widget.AbsListView;
import android.widget.ListView;

/**
 * SwipeRefreshLayout 非直接包裹ListView时,刷新list用
 * Created by Administrator on 2016/10/27.
 */
public class LayoutRefreshLayout extends SwipeRefreshLayout {
    private ListView lv;

    public LayoutRefreshLayout(Context context) {
        super(context);
    }

    public LayoutRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setViewGroup(ListView lv) {
        this.lv = lv;
    }

    @Override
    public boolean canChildScrollUp() {
        if (lv != null && lv instanceof AbsListView) {
            AbsListView absListView = lv;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        }
        return super.canChildScrollUp();

    }

}
